home *** CD-ROM | disk | FTP | other *** search
/ GameStar 1998 November (Bonus) / GAMESTAR11B.ISO / ENCYC99 / MM / T620272A.DCR / Scripts_12_Class KeyMaster.ls < prev    next >
Encoding:
Text File  |  1998-06-29  |  6.4 KB  |  207 lines

  1. property calcButton, theBrain, contributionField, interestField, ContributionValue, InterestValue, InterestFieldSelected, currentField, acceptKeys, interestCursor, contributionCursor, DELETE_KEY
  2.  
  3. on tabKey me
  4.   set InterestFieldSelected to not InterestFieldSelected
  5.   if InterestFieldSelected then
  6.     set currentField to interestField
  7.     set the visible of sprite interestCursor to 1
  8.     set the visible of sprite contributionCursor to 0
  9.     set the text of interestField to " "
  10.     set InterestValue to 0
  11.     setInterestRate(theBrain, 0)
  12.     turnOff(calcButton)
  13.   else
  14.     set currentField to contributionField
  15.     set the visible of sprite contributionCursor to 1
  16.     set the visible of sprite interestCursor to 0
  17.     set the text of contributionField to " "
  18.     set ContributionValue to 0
  19.     setMonthlyContribution(theBrain, 0)
  20.     turnOff(calcButton)
  21.   end if
  22.   set acceptKeys to 1
  23. end
  24.  
  25. on keyPress me, xKey
  26.   if acceptKeys then
  27.     case xKey of
  28.       BACKSPACE:
  29.         if InterestFieldSelected then
  30.           set interestString to the text of interestField
  31.           if InterestValue = 0 then
  32.             if floatp(InterestValue) then
  33.               if the last char in interestString = "." then
  34.                 set InterestValue to 0
  35.                 set interestString to " "
  36.               else
  37.                 delete char -30000 of interestString
  38.               end if
  39.             else
  40.               set interestString to " "
  41.             end if
  42.           else
  43.             if floatp(InterestValue) then
  44.               if the last char in interestString = "." then
  45.                 set InterestValue to integer(InterestValue * 10) / 10
  46.                 set interestString to string(InterestValue)
  47.               else
  48.                 delete char -30000 of interestString
  49.               end if
  50.             else
  51.               if InterestValue < 10 then
  52.                 set interestString to " "
  53.                 set InterestValue to 0
  54.               else
  55.                 delete char -30000 of interestString
  56.               end if
  57.             end if
  58.           end if
  59.           set tempString to interestString
  60.           if tempString contains "," then
  61.             set whichPos to offset(tempString, ",")
  62.             put "." into char whichPos of tempString
  63.           end if
  64.           set InterestValue to value(tempString)
  65.         else
  66.           set ContributionValue to ContributionValue / 10
  67.           if ContributionValue <> 0 then
  68.             set contributionString to moneyFormat(ContributionValue)
  69.           else
  70.             set contributionString to " "
  71.           end if
  72.         end if
  73.       DELETE_KEY, "c", "C":
  74.         if InterestFieldSelected then
  75.           set InterestValue to 0
  76.           set interestString to " "
  77.         else
  78.           set ContributionValue to 0
  79.           set contributionString to " "
  80.         end if
  81.       RETURN:
  82.         mouseEvent(calcButton, #mouseEnter)
  83.         mouseEvent(calcButton, #mouseDown)
  84.         mouseEvent(calcButton, #mouseUp)
  85.         mouseEvent(calcButton, #mouseGone)
  86.       otherwise:
  87.         if InterestFieldSelected then
  88.           set interestString to the text of interestField
  89.           if the number of chars in interestString < 5 then
  90.             if the key = "," then
  91.               if floatp(InterestValue) then
  92.                 beep()
  93.               else
  94.                 if InterestValue = 0 then
  95.                   set interestString to "0,"
  96.                 else
  97.                   put "," after interestString
  98.                 end if
  99.                 set InterestValue to float(InterestValue)
  100.               end if
  101.             else
  102.               if xKey >= "0" then
  103.                 if xKey <= "9" then
  104.                   if not floatp(InterestValue) then
  105.                     if InterestValue <> 0 then
  106.                       put xKey after interestString
  107.                     else
  108.                       set interestString to xKey
  109.                     end if
  110.                   else
  111.                     put xKey after interestString
  112.                   end if
  113.                 else
  114.                   beep()
  115.                 end if
  116.               end if
  117.             end if
  118.             set InterestValue to value(interestString)
  119.           end if
  120.         else
  121.           if xKey >= "0" then
  122.             if xKey <= "9" then
  123.               if ContributionValue < 1000 then
  124.                 set ContributionValue to (ContributionValue * 10) + value(xKey)
  125.                 if ContributionValue <> 0 then
  126.                   set contributionString to moneyFormat(ContributionValue)
  127.                 else
  128.                   set contributionString to " "
  129.                 end if
  130.               else
  131.                 beep()
  132.               end if
  133.             else
  134.               beep()
  135.             end if
  136.           else
  137.             beep()
  138.           end if
  139.         end if
  140.     end case
  141.     if InterestFieldSelected then
  142.       if not voidp(interestString) then
  143.         set the text of interestField to interestString
  144.       end if
  145.     else
  146.       if not voidp(contributionString) then
  147.         set the text of contributionField to contributionString
  148.       end if
  149.     end if
  150.     setInterestRate(theBrain, InterestValue)
  151.     setMonthlyContribution(theBrain, ContributionValue)
  152.     if the text of interestField = " " then
  153.       turnOff(calcButton)
  154.     else
  155.       if the text of contributionField = " " then
  156.         turnOff(calcButton)
  157.       else
  158.         turnON(calcButton)
  159.       end if
  160.     end if
  161.     put InterestValue
  162.     put ContributionValue
  163.   end if
  164. end
  165.  
  166. on selectInterestField me
  167.   set InterestFieldSelected to 0
  168.   tabKey(me)
  169. end
  170.  
  171. on selectContributionField me
  172.   set InterestFieldSelected to 1
  173.   tabKey(me)
  174. end
  175.  
  176. on refuseKeys me
  177.   set acceptKeys to 0
  178.   set the visible of sprite interestCursor to 0
  179.   set the visible of sprite contributionCursor to 0
  180. end
  181.  
  182. on new me
  183.   set contributionField to member "Contribution Input"
  184.   set interestField to member "Interest Input"
  185.   set ContributionValue to 0
  186.   set InterestValue to 0
  187.   set InterestFieldSelected to 0
  188.   set currentField to contributionField
  189.   set DELETE_KEY to 127
  190.   set interestCursor to 24
  191.   set contributionCursor to 23
  192.   puppetSprite(interestCursor, 1)
  193.   puppetSprite(contributionCursor, 1)
  194.   set the visible of sprite interestCursor to 0
  195.   set the visible of sprite contributionCursor to 0
  196.   set InterestFieldSelected to 1
  197.   set acceptKeys to 0
  198.   return me
  199. end
  200.  
  201. on linkUp me, xButton, xBrain
  202.   set calcButton to xButton
  203.   set theBrain to xBrain
  204.   setInterestRate(theBrain, InterestValue)
  205.   setMonthlyContribution(theBrain, ContributionValue)
  206. end
  207.